// 定义请求后端接口的方法
// 利用模块化操作

import request from '@/utils/request.js'

const api_name = '/cms/book'

export default {
  // 带分页的条件查询
  query(pageNo, pageSize, bookQuery) {
    // 调用后端接口 axios发出异步请求
    return request({
      url: `${api_name}/${pageNo}/${pageSize}`,
      method: 'post',
      data: bookQuery
    })
  },
  add(book) {
    return request({
      url: `${api_name}/saveBook`,
      method: 'post',
      data: book
    })
  },
  // 修改
  update(book) {
    return request({
      url: `${api_name}/updateBook`,
      method: 'put',
      data: book
    })
  },
  // 回显
  view(id) {
    return request({
      url: `${api_name}/${id}`,
      method: 'get'
    })
  },
  delete(id) {
    return request({
      url: `${api_name}/${id}`,
      method: 'delete'
    })
  },
  upOrDownBook(id, online) {
    return request({
      url: `${api_name}/upOrDownBook/${id}/${online}`,
      method: 'put'
    })
  }
}
